package com.yourname.lab4.v1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Exercise {
    private List<Expression> expressions;

    public Exercise() {
        this.expressions = new ArrayList<>();
    }

    public void addExpression(Expression exp) {
        expressions.add(exp);
    }

    public void generateAddition(int count) {
        Random rand = new Random();
        for (int i = 0; i < count; i++) {
            int left = rand.nextInt(100);  // 0-99
            int right = rand.nextInt(100);
            expressions.add(new Expression(left, right, '+'));
        }
    }

    public void generateSubtraction(int count) {
        Random rand = new Random();
        for (int i = 0; i < count; i++) {
            int left = rand.nextInt(100) + 1;  // 1-100，避免负数
            int right = rand.nextInt(left);    // 确保结果非负
            expressions.add(new Expression(left, right, '-'));
        }
    }

    public void display() {
        for (int i = 0; i < expressions.size(); i++) {
            System.out.println((i + 1) + ". " + expressions.get(i));
        }
    }

    public List<Expression> getExpressions() {
        return expressions;
    }
}